﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using WPFTrees.DataStructures;
using WPFTrees.Parser;

namespace WPFTrees.Tests
{
    [TestFixture]
    class ParserTest
    {
        [Test]
        /*SKIPPED*/ void TestTreeWithOneNode()
        {
            NTreeNode<NewickNode> root = new NTreeNode<NewickNode>(new NewickNode("",false),1);
            NTreeNode<NewickNode> onlyChild = new NTreeNode<NewickNode>(new NewickNode("a",true),0);
            root.AddNode(onlyChild);
            
            NTree<NewickNode> tree = Parser.NewickParser.Parse("(a);");

            NTreeNode<NewickNode> actualRoot = tree.GetRoot();
            Assert.AreEqual(root, actualRoot);
            Assert.AreEqual(root.Children[0].Value(),actualRoot.Children[0].Value());
            Assert.AreEqual(root.CountChildren, actualRoot.CountChildren);
        }

        [Test]
        public void TestBranchLenghts()
        {
            NTree<NewickNode> tree = Parser.NewickParser.Parse("(a:5,b:0.5,c:5.0,d:.5,e):2.4;");
            NTreeNode<NewickNode> node1 = tree.GetRoot().Children[0];
            Assert.AreEqual("a",node1.Value().Label);
            Assert.AreEqual(5.0,node1.Value().BranchLenght);
            NTreeNode<NewickNode> node2 = tree.GetRoot().Children[1];
            Assert.AreEqual("b",node2.Value().Label);
            Assert.AreEqual(0.5,node2.Value().BranchLenght);
            NTreeNode<NewickNode> node3 = tree.GetRoot().Children[2];
            Assert.AreEqual("c",node3.Value().Label);
            Assert.AreEqual(5.0,node3.Value().BranchLenght);
            NTreeNode<NewickNode> node4 = tree.GetRoot().Children[3];
            Assert.AreEqual("d",node4.Value().Label);
            Assert.AreEqual( 0.5,node4.Value().BranchLenght);

            NTreeNode<NewickNode> node5 = tree.GetRoot().Children[4];
            Assert.AreEqual("e",node5.Value().Label);
            Assert.AreEqual(null, node5.Value().BranchLenght);

            Assert.AreEqual(2.4, tree.GetRoot().Value().BranchLenght);
        }


        [Test]
        //
        // !!! neprojde, kvuli chybejicimu stredniku!!! 
        // Je to chyba? Podle spec. formatu je strednik povinny, vetsina parseru to umi bez nej.
        //
        /* EXCLUDED*/ void TestBranchLenghtsNoSemicolon()
        {
            NTree<NewickNode> tree = Parser.NewickParser.Parse("(a:5,b:0.5,c:5.0,d:.5,e):2.4");
            NTreeNode<NewickNode> node1 = tree.GetRoot().Children[0];
            Assert.AreEqual("a", node1.Value().Label);
            Assert.AreEqual(5.0, node1.Value().BranchLenght);
            NTreeNode<NewickNode> node2 = tree.GetRoot().Children[1];
            Assert.AreEqual("b", node2.Value().Label);
            Assert.AreEqual(0.5, node2.Value().BranchLenght);
            NTreeNode<NewickNode> node3 = tree.GetRoot().Children[2];
            Assert.AreEqual("c", node3.Value().Label);
            Assert.AreEqual(5.0, node3.Value().BranchLenght);
            NTreeNode<NewickNode> node4 = tree.GetRoot().Children[3];
            Assert.AreEqual("d", node4.Value().Label);
            Assert.AreEqual(0.5, node4.Value().BranchLenght);

            NTreeNode<NewickNode> node5 = tree.GetRoot().Children[4];
            Assert.AreEqual("e", node5.Value().Label);
            Assert.AreEqual(null, node5.Value().BranchLenght);

            Assert.AreEqual(2.4, tree.GetRoot().Value().BranchLenght);
        }
    }
}
